namespace SinaFinance.ChartLibrary.AxisLibrary
{
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;

    public partial class StockChartCover : UserControl
    {
        //private bool _contentLoaded;
        private double chartAreaHeight = 0.0;
        private double chartAreaWidth = 0.0;
        private EventHandler closeStockChartCover;
        private string currentStockID = string.Empty;
        //internal Grid LayoutRoot;
        //internal Canvas rootCanvas;
        private double screemHeight = 0.0;
        private double screemWidth = 0.0;
        private string stockNumber = string.Empty;
        private StockChartTypeEnum type = StockChartTypeEnum.TimeSharing;

        public event EventHandler CloseStockChartCover
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.closeStockChartCover = (EventHandler)Delegate.Combine((Delegate)this.closeStockChartCover, (Delegate)value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.closeStockChartCover = (EventHandler)Delegate.Remove((Delegate)this.closeStockChartCover, (Delegate)value);
            }
        }

        public StockChartCover()
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.StockChartCover_Loaded);
        }

        //[DebuggerNonUserCode]
        //public void InitializeComponent()
        //{
        //    if (!this._contentLoaded)
        //    {
        //        this._contentLoaded = true;
        //        Application.LoadComponent(this, new Uri("/SinaFinance;component/ChartLibrary/AxisLibrary/StockChartCover.xaml", UriKind.Relative));
        //        this.LayoutRoot = (Grid) base.FindName("LayoutRoot");
        //        this.rootCanvas = (Canvas) base.FindName("rootCanvas");
        //    }
        //}

        protected void RenderStockChart()
        {
            if (this.type.Equals(StockChartTypeEnum.TimeSharing))
            {
                TimeSharingAxis axis = new TimeSharingAxis {
                    Width = this.chartAreaWidth,
                    Height = this.chartAreaHeight,
                    Margin = new Thickness(10.0, 20.0, 0.0, 0.0),
                    StockNumber = this.currentStockID.Trim().Equals(string.Empty) ? this.stockNumber : this.currentStockID,
                    IsFullScreem = false
                };
                this.rootCanvas.Children.Add(axis);
            }
            if (this.type.Equals(StockChartTypeEnum.KLine))
            {
                KDayAxis axis2 = new KDayAxis {
                    Width = this.chartAreaWidth,
                    Height = this.chartAreaHeight,
                    Margin = new Thickness(10.0, 20.0, 0.0, 0.0),
                    StockNumber = this.stockNumber
                };
                this.rootCanvas.Children.Add(axis2);
            }
        }

        private void StockChartCover_Loaded(object sender, RoutedEventArgs e)
        {
            if (!this.stockNumber.Trim().Equals(string.Empty))
            {
                this.rootCanvas.Children.Clear();
                this.screemHeight = Application.Current.Host.Content.ActualHeight;
                this.screemWidth = Application.Current.Host.Content.ActualWidth;
                this.rootCanvas.Width = this.screemWidth;
                this.rootCanvas.Height = this.screemHeight;
                LinearGradientBrush brush = new LinearGradientBrush();
                GradientStop stop = new GradientStop();
                GradientStop stop2 = new GradientStop();
                GradientStop stop3 = new GradientStop();
                stop.Color = Color.FromArgb(0xff, 0, 0, 0);
                stop.Offset = 0.0;
                stop2.Color = Color.FromArgb(0xff, 0x13, 0x1b, 0x29);
                stop2.Offset = 0.5;
                stop3.Color = Color.FromArgb(0xff, 0x1c, 0x2e, 0x41);
                stop3.Offset = 1.0;
                brush.StartPoint = new Point(0.0, 0.0);
                brush.EndPoint = new Point(0.0, 1.0);
                brush.GradientStops.Add(stop);
                brush.GradientStops.Add(stop2);
                brush.GradientStops.Add(stop3);
                this.rootCanvas.Background = brush;
                this.chartAreaWidth = this.screemWidth - 20.0;
                this.chartAreaHeight = ((this.chartAreaWidth / 2.0) > this.screemHeight) ? (this.screemHeight - 20.0) : (this.chartAreaWidth / 2.0);
                this.RenderStockChart();
                bool flag = false;
                for (int i = 0; i < this.LayoutRoot.Children.Count; i++)
                {
                    if (this.LayoutRoot.Children[i].GetValue(FrameworkElement.NameProperty).ToString().Equals("closeIcon"))
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                }
            }
        }

        private void StockChartCover_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.closeStockChartCover != null)
            {
                this.closeStockChartCover(sender, e);
            }
        }

        public string CurrentStockID
        {
            get
            {
                return this.currentStockID;
            }
            set
            {
                this.currentStockID = value;
            }
        }

        public string StockNumber
        {
            get
            {
                return this.stockNumber;
            }
            set
            {
                this.stockNumber = value;
            }
        }

        public StockChartTypeEnum Type
        {
            get
            {
                return this.type;
            }
            set
            {
                this.type = value;
            }
        }

        public delegate void EventHandler(object sender, MouseEventArgs e);

        public enum StockChartTypeEnum
        {
            KLine = 2,
            TimeSharing = 1
        }
    }
}
